const Router = require('koa-router')
const selectlogin = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
  database: 'running',
  user: 'run',
  port: 5432,
  host: '82.157.94.115',
  password: 'z12345678',
  max: 2
})

selectlogin.get('/selectlogin', async ctx => {
  let searchContentPostgresql = `select * from login`;
  let content = await psql.query(searchContentPostgresql);
  if (content.rowCount > 0) {
    var selectloginObj=[];
    for (var i = 0; i < content.rowCount; i++) {
      var obj = {
        username: content.rows[i].username,
        openid: content.rows[i].openid
      }
      
      selectloginObj.push(obj);
    }

    ctx.body = {
        selectloginObj
    };
  }


})

module.exports = selectlogin